<template>
    <div class="detail">
        <div class="content">
            <Row type="flex" justify="center">
                <Col span="24" style="text-align: left">
                    <h1 style="color: #17233d; margin-bottom: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" >{{ post.title}}</h1>
                </Col>
            </Row>
            <Row type="flex" justify="center">
                <Col span="12" style="text-align: left">
                    <h3 style="color: #515a6e; margin-bottom: 5px;">分类: {{filterColumn('categoryList', post.catId)[0]?filterColumn('categoryList', post.catId)[0].catName: ''}}</h3>
                </Col>
                <Col span="12" style="text-align: right">
                    <h3 style="color: #515a6e; margin-bottom: 5px;">作者: JavaDog程序狗</h3>
                </Col>
            </Row>

            <Row type="flex" justify="center">
                <Col span="12" style="text-align: left">
                    <h4 style="color: #515a6e; margin-bottom: 5px;">标签:  <Tag v-for="item in tagListData" :key="item.id" :color="item.color" size="mini" @click.native="tagClick(item)">{{ item.tagName }}</Tag></h4>
                </Col>
                <Col span="12" style="text-align: right">
                    <h4 style="color: #515a6e">发布时间: {{ formatDate(post.updateTime)}}</h4>
                </Col>
            </Row>
            <Divider />
            <Row type="flex" justify="center">
                <Col span="24">
                    <div class="markdown_views" v-html="post.convertContent"></div>
                </Col>
            </Row>
        </div>
    </div>
</template>

<script>
import moment from 'moment'

export default {
    name: 'blog',
    data() {
        return {
            post: {},
            // 分类数据源
            categoryList: [],
            // 标签数据源
            tagList: [],
            // 标签
            tagListData: [],
        }
    },
    methods: {
        async init(articleId) {
            await this.articleDetail(articleId)
            await this.dataSource()
            await this.tagDataCovert()
        },
        // 标签数据
        tagDataCovert() {
            const tagListData = this.filterColumnTag('tagList', this.post.tagIds)
            this.tagListData = tagListData
        },
        // 文章详情
        async articleDetail(articleId) {
            const res = await this.$api.articleDetail(articleId)
            if (!res.success) {
                this.$Message.error(res.message)
                return false
            }
            this.post = res.data
        },
        // 格式化时间
        formatDate(updateTime) {
            return moment(updateTime).format('yyyy-MM-DD HH:mm:ss')
        },
        // 加载数据源
        async dataSource() {
            await this.categoryData()
            await this.tagData()
        },
        // 分类数据源
        async categoryData() {
            const res = await this.$api.categoryList()
            if (!res.success) {
                this.$Message.error(res.message)
                return false
            }
            this.categoryList = res.data
        },
        // 标签数据源
        async tagData() {
            const res = await this.$api.tagList()
            if (!res.success) {
                this.$Message.error(res.message)
                return false
            }
            this.tagList = res.data
        },
        // 过滤
        filterColumn(dataSource, target) {
            // eslint-disable-next-line no-return-assign
            const targetArr = this[dataSource].filter(item => item.id == target)
            return targetArr
        },
        // 过滤标签
        filterColumnTag(dataSource, target) {
            // eslint-disable-next-line no-return-assign
            const targetArr = this[dataSource].filter(item => target.includes(item.id))
            return targetArr
        },
    },
    mounted() {
        const articleId = this.$route.query.articleId
        this.init(articleId)
    },

}
</script>

<style scoped>

.detail{
    overflow-y: scroll;
    background: url('../../assets/imgs/bg.png') repeat;
}
::v-deep img{
    max-width:100%;
}
.content{
    width: 60%;
    margin: 0 auto;
    position: relative;
    padding: 24px 24px 16px;
    background: #fff;
    border-radius: 2px;
}
</style>

<style>
::-webkit-scrollbar {
    width: 6px;
    background-color: #d8d8d8;
}

/* 滚动槽 */
::-webkit-scrollbar-track {
    border-radius:10px;
}

::-webkit-scrollbar-thumb {
    background-color: #bfc1c4;
}
pre{
    white-space:pre-wrap;
    white-space:-moz-pre-wrap;
    white-space:-o-pre-wrap;
    word-wrap:break-word;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0 0 24px;
    overflow-x: auto;
    padding: 8px;
}

.htmledit_views address,.htmledit_views cite,.htmledit_views dfn,.htmledit_views em,.htmledit_views i,.htmledit_views span[lang],.htmledit_views var {
    font-style: italic
}

.htmledit_views {
    font-family: -apple-system,SF UI Text,Arial,PingFang SC,Hiragino Sans GB,Microsoft YaHei,WenQuanYi Micro Hei,sans-serif,SimHei,SimSun
}

.markdown_views blockquote,.markdown_views dl,.markdown_views ol,.markdown_views p,.markdown_views pre,.markdown_views ul {
    margin: 1.2em 0
}

.markdown_views ol ol,.markdown_views ol ul,.markdown_views ul ol,.markdown_views ul ul {
    margin: 0
}

.markdown_views dt {
    font-weight: 700
}

.markdown_views code *,.markdown_views pre *,.markdown_views samp * {
    font-size: inherit
}

.markdown_views blockquote {
    color: rgba(0,0,0,.5);
    padding-left: 1.5em
}

.app--dark .layout__panel--editor .markdown_views blockquote,.app--dark .layout__panel--preview .markdown_views blockquote {
    color: hsla(0,0%,100%,.4);
    border-left-color: hsla(0,0%,100%,.075)
}

.markdown_views code {
    padding: 2px 4px
}

.markdown_views pre>code {
    background-color: rgba(0,0,0,.05);
    display: block;
    padding: .5em;
    -webkit-text-size-adjust: none;
    overflow-x: auto;
    white-space: pre
}

.markdown_views .toc ul {
    list-style-type: none;
    padding-left: 20px
}

.markdown_views table {
    background-color: transparent;
    border-spacing: 0
}

.markdown_views td,.markdown_views th {
    border-right: 1px solid #dcdcdc;
    padding: 8px 24px
}

.markdown_views td {
    border-top: 1px solid #dcdcdc
}

.markdown_views mark {
    background-color: #f8f840
}

.markdown_views abbr[title] {
    cursor: help
}

.markdown_views img[src*="#pic_center"] {
    display: block;
    margin: auto
}

.markdown_views img[src*="#pic_right"] {
    display: block;
    margin: auto 0 auto auto
}

.markdown_views .task-list-item {
    list-style-type: none
}

.markdown_views .task-list-item p {
    overflow: unset
}

.markdown_views .task-list-item-checkbox {
    margin: 0 .2em 0 -1.3em
}

.markdown_views .page-break-after {
    page-break-after: always
}

.markdown_views .stackedit__html {
    margin-bottom: 180px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 30px;
    padding-right: 30px;
    max-width: 750px
}

.markdown_views .stackedit__toc ul {
    padding: 0
}

.markdown_views .stackedit__toc ul a {
    margin: .5rem 0;
    padding: .5rem 1rem
}

.markdown_views .stackedit__toc ul ul {
    color: #888;
    font-size: .9em
}

.markdown_views .stackedit__toc ul ul a {
    margin: 0;
    padding: .1rem 1rem
}

.markdown_views .stackedit__toc li {
    display: block
}

.markdown_views .stackedit__toc a {
    display: block;
    color: inherit;
    text-decoration: none
}

.markdown_views .stackedit__toc a:active,.markdown_views .stackedit__toc a:focus,.markdown_views .stackedit__toc a:hover {
    background-color: rgba(0,0,0,.075);
    border-radius: 4px
}

.markdown_views .stackedit__left {
    position: fixed;
    display: none;
    width: 250px;
    height: 100%;
    top: 0;
    left: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none
}

.markdown_views .stackedit__right {
    position: absolute;
    right: 0;
    top: 0;
    left: 0
}

@media (min-width: 1060px) {
    .markdown_views .stackedit__left {
        display:block
    }

    .markdown_views .stackedit__right {
        left: 250px
    }
}

.markdown_views .stackedit--pdf blockquote {
    border-left-color: #ececec
}

.markdown_views .stackedit--pdf .stackedit__html {
    padding-left: 0;
    padding-right: 0;
    max-width: none
}

.markdown_views {
    word-break: break-word!important;
    -moz-osx-font-smoothing: antialiased;
    font-variant-ligatures: no-common-ligatures
}

.markdown_views p {
    font-size: 16px;
    color: #4d4d4d;
    font-weight: 400;
    line-height: 26px;
    margin: 0 0 16px;
    overflow: hidden;
    overflow-x: auto
}

.markdown_views strong {
    font-weight: 700
}

.markdown_views i,address,cite,dfn,em,var {
    font-style: italic
}

.markdown_views h1,.markdown_views h2,.markdown_views h3,.markdown_views h4,.markdown_views h5,.markdown_views h6 {
    color: #4f4f4f;
    margin: 24px 0 8px;
    font-weight: 600
}

.markdown_views ol,.markdown_views ul {
    margin: 0 0 24px;
    padding: 0;
    font-size: 16px;
    overflow: hidden;
    overflow-x: auto
}

.markdown_views ol,.markdown_views ol>li {
    list-style-type: decimal!important
}

.markdown_views ul,.markdown_views ul>li {
    list-style-type: disc
}

.markdown_views ol ul,.markdown_views ol ul>li,.markdown_views ul ul,.markdown_views ul ul li {
    list-style-type: circle
}

.markdown_views ol ol,.markdown_views ol ol>li,.markdown_views ol ul ul,.markdown_views ol ul ul>li,.markdown_views ul ol,.markdown_views ul ol>li,.markdown_views ul ul ul,.markdown_views ul ul ul li {
    list-style-type: square
}

.markdown_views li {
    margin: 8px 0 0 32px
}

.markdown_views p>img {
    max-width: 100%;
    margin: 0
}

.markdown_views img {
    margin: 24px 0;
    max-width: 100%
}

.markdown_views h1 {
    font-size: 22px;
    line-height: 32px
}

.markdown_views h2 {
    font-size: 20px;
    line-height: 30px
}

.markdown_views h3 {
    font-size: 18px;
    line-height: 28px
}

.markdown_views h4 {
    font-size: 16px;
    line-height: 26px
}

.markdown_views h5,.markdown_views h6 {
    font-size: 16px;
    line-height: 24px
}

.markdown_views h1 code {
    font-size: 28px
}

.markdown_views h2 code {
    font-size: 24px
}

.markdown_views h3 code {
    font-size: 22px
}

.markdown_views h4 code {
    font-size: 20px
}

.markdown_views h5 code {
    font-size: 18px
}

.markdown_views h6 code {
    font-size: 16px
}

.markdown_views blockquote {
    display: block;
    padding: 16px;
    margin: 0 0 24px;
    border-left: 8px solid #dddfe4;
    background: #eef0f4;
    overflow: auto;
    word-break: break-word!important
}

.markdown_views blockquote ol,.markdown_views blockquote ul {
    margin-bottom: 0;
    padding: 0;
    font-size: 14px;
    line-height: 22px
}

.markdown_views blockquote ol li,.markdown_views blockquote ul li {
    margin-bottom: 0
}

.markdown_views blockquote p {
    font-size: 14px;
    line-height: 22px;
    color: #555666;
    font-weight: 400;
    margin-bottom: 0
}

.markdown_views hr {
    margin: 24px 0;
    border: none;
    border-bottom: 1px solid #ddd
}

.markdown_views table tr {
    border: 0;
    border-top: 1px solid #ddd;
    background-color: #fff
}

.markdown_views table {
    border-collapse: collapse;
    display: table;
    width: 100%;
    text-align: center;
    margin-bottom: 24px
}

.markdown_views tbody {
    border: 0
}

.markdown_views table tr:nth-child(2n) {
    background-color: #f7f7f7
}

.markdown_views table tr td,.markdown_views table tr th {
    font-size: 14px;
    color: #4f4f4f;
    line-height: 22px;
    border: 1px solid #ddd;
    padding: 8px;
    word-break: normal!important;
    vertical-align: middle
}

.markdown_views table tr td code,.markdown_views table tr th code {
    white-space: normal;
    word-break: normal!important
}

.markdown_views table tr th {
    font-weight: 700;
    background-color: #eff3f5
}

.markdown_views dl {
    margin: 24px
}

.markdown_views dl dt {
    margin: 8px;
    font-weight: 700
}

.markdown_views dl dt dd {
    margin: 8px
}

.markdown_views abbr[data-original-title],.markdown_views abbr[title] {
    cursor: help;
    border-bottom: 1px dotted #999
}

.markdown_views .initialism {
    font-size: 90%;
    text-transform: uppercase
}

.markdown_views pre {
    margin-bottom: 24px
}

.markdown_views pre code {
    color: unset
}

.markdown_views code,.markdown_views kbd,.markdown_views pre,.markdown_views samp {
    font-family: Source Code Pro,DejaVu Sans Mono,Ubuntu Mono,Anonymous Pro,Droid Sans Mono,Menlo,Monaco,Consolas,Inconsolata,Courier,monospace,PingFang SC,Microsoft YaHei,sans-serif;
    font-size: 14px;
    line-height: 22px;
    color: #000
}

.markdown_views code {
    color: #c7254e;
    background-color: #f9f2f4;
    border-radius: 2px
}

.markdown_views a {
    text-decoration-skip: ink;
    color: #4ea1db;
    text-decoration: none
}

.markdown_views a:focus,.markdown_views a:hover {
    text-decoration: none;
    color: #ca0c16
}

.markdown_views a:visited {
    color: #6795b5
}

.markdown_views .footnote {
    vertical-align: top;
    position: relative;
    top: -4px;
    font-size: 24px
}

.markdown_views .footnotes ol li {
    font-size: 14px;
    line-height: 22px;
    margin: 0 0 8px 24px
}

.markdown_views .flow-chart,.markdown_views .sequence-diagram {
    text-align: center;
    margin-bottom: 24px;
    font-size: 14px!important
}

.markdown_views .flow-chart svg,.markdown_views .sequence-diagram svg {
    width: unset
}

.markdown_views .flow-chart [fill="#000000"],.markdown_views .flow-chart [fill="#000"],.markdown_views .flow-chart [fill=black],.markdown_views .sequence-diagram [fill="#000000"],.markdown_views .sequence-diagram [fill="#000"],.markdown_views .sequence-diagram [fill=black] {
    fill: #4f4f4f
}

.markdown_views .flow-chart [stroke="#000000"],.markdown_views .sequence-diagram [stroke="#000000"] {
    stroke: #4f4f4f
}

.markdown_views .MathJax_SVG_Display {
    text-align: center;
    margin: 24px 0;
    font-size: 18px;
    font-weight: 400;
    color: #4f4f4f;
    position: relative;
    text-indent: 0;
    max-width: none;
    max-height: none;
    min-width: 0;
    min-height: 0;
    width: 100%
}

.markdown_views .toc {
    font-size: 18px;
    line-height: 24px;
    margin: 0 0 24px;
    padding: 0
}

.markdown_views .toc ul {
    margin: 0 0 8px;
    padding: 0
}

.markdown_views .toc ul ul {
    padding-left: 24px
}

.markdown_views .toc ul li {
    list-style-type: none;
    margin: 8px 0 0 24px
}

.markdown_views dl dd {
    margin: 0 0 8px 40px
}

.markdown_views kbd {
    padding: 2px 8px;
    border: 1px solid rgba(63,63,63,.25);
    box-shadow: 0 1px 0 rgba(63,63,63,.25);
    background-color: #fff;
    color: #333;
    border-radius: 4px;
    display: inline-block;
    margin: 0 2px;
    white-space: nowrap
}

.markdown_views .katex-display {
    overflow: hidden;
    overflow-x: auto;
    padding: 6px 0
}

.markdown_views .katex .vlist-t2 {
    margin-right: 0!important
}
</style>
